/*
 * 商品信息管理.java
 *
 * Created on __DATE__, __TIME__
 */



import javafx.scene.control.Labeled;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author  __USER__
 */
public class 商品信息管理 extends javax.swing.JFrame {

	/** Creates new form 商品信息管理 */
	public 商品信息管理() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
				Short.MAX_VALUE));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				商品信息管理 商品信息管理sp = new 商品信息管理();
				try {
					商品信息管理sp.connect();
				} catch (ClassNotFoundException ex) {
					throw new RuntimeException(ex);
				} catch (SQLException ex) {
					throw new RuntimeException(ex);
				}
				商品信息管理sp.setVisible(true);
			}
		});
	}
	//自定义方法
	//连接数据库
	public void connect() throws ClassNotFoundException, SQLException {
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		String dburl = "jdbc:sqlserver://127.0.0.1:1433;DataBaseName=webstore";
	    Connection con = DriverManager.getConnection(dburl,"sa","123456");
		String sql = "SELECT * FROM products";
		Statement stmt = con.createStatement();
		ResultSet rst = stmt.executeQuery(sql);
		if(rst.next()){
			bindshow();//自定义方法：在界面显示数据
		}
	}catch(SQLException e) {
    		e.printStackTrace();
    	}
    	//绑定界面组件
    	public void bindshow() throws SQLException {
			Labeled jTextField1;
			jTextField1 = null;
			jTextField1.setText(rst.getString(1));
			Labeled jTextField2;
			jTextField2 = null;
			jTextField2.setText(rst.getString(2));
			Labeled jTextField3;
			jTextField3 = null;
			jTextField3.setText(rst.getString(3));
			Labeled jTextField4;
			jTextField4 = null;
			jTextField4.setText(rst.getString(4));
			Labeled jTextField5;
			jTextField5 = null;
			jTextField5.setText(rst.getString(5));
    		
    	}
	//自定义变量
	Connection con;
	Statement stmt;
	ResultSet rst;
	

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	// End of variables declaration//GEN-END:variables

}